[id].vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="admin--page-content">
  3. <div class="admin--sub--table--title">
  4. <p>{{ areaName ? `${areaName} 낚시어선 / 낚시터` : "낚시어선 / 낚시터" }}</p>
  5. <div class="sub--table--info">
  6. <span>🎣 낚시터 {{ fishingCount }}</span>
  7. <span>🚢 낚시어선 {{ onboardCount }}</span>
  8. </div>
  9. </div>
  10. <div class="admin--table-wrapper">
  11. <table class="admin--table">
  12. <thead>
  13. <tr>
  14. <th style="width: 80px;">번호</th>
  15. <th style="width: 180px;">구분</th>
  16. <th>이름</th>
  17. <th>주소</th>
  18. <th>상태</th>
  19. <th style="width: 120px;">등록일</th>
  20. </tr>
  21. </thead>
  22. <tbody>
  23. <tr v-if="isLoading">
  24. <td colspan="6" class="admin--table-loading">데이터를 불러오는 중...</td>
  25. </tr>
  26. <tr v-else-if="!places || places.length === 0">
  27. <td colspan="6" class="admin--table-empty">해당 지역에 등록된 낚시어선/낚시터가 없습니다.</td>
  28. </tr>
  29. <tr
  30. v-else
  31. v-for="(p, index) in places"
  32. :key="p.place_type + '-' + p.id"
  33. class="admin--table-row-clickable"
  34. @click="goToPlace(p)"
  35. >
  36. <td class="date">{{ totalCount - ((currentPage - 1) * perPage + index) }}</td>
  37. <td>
  38. <span :class="['admin--badge', p.place_type === 'onboard' ? 'admin--badge-active' : 'admin--badge-html']">
  39. {{ p.place_type === "onboard" ? "낚시어선" : "낚시터" }}
  40. </span>
  41. </td>
  42. <td class="admin--table-title">{{ p.name }}</td>
  43. <td>{{ p.address || "-" }}</td>
  44. <td>
  45. <span :class="['admin--badge', p.status_YN === 'Y' ? 'admin--badge-active' : 'admin--badge-ended']">
  46. {{ p.status_YN === "Y" ? "사용중" : "미사용" }}
  47. </span>
  48. </td>
  49. <td class="date">{{ formatDate(p.created_at) }}</td>
  50. </tr>
  51. </tbody>
  52. </table>
  53. </div>
  54. <div class="admin--place--btn--wrap">
  55. <!-- 버튼 영역 -->
  56. <div class="admin--form-actions">
  57. <button type="button" class="admin--btn" @click="goBack">
  58. ← 지역 상세로
  59. </button>
  60. </div>
  61. <!-- 페이지네이션 -->
  62. <div v-if="totalPages > 1" class="admin--pagination">
  63. <button
  64. v-if="totalPages > 2"
  65. class="admin--pagination-btn"
  66. :disabled="currentPage === 1"
  67. @click="changePage(1)"
  68. title="처음"
  69. >◀◀</button>
  70. <button
  71. class="admin--pagination-btn"
  72. :disabled="currentPage === 1"
  73. @click="changePage(currentPage - 1)"
  74. title="이전"
  75. >◀</button>
  76. <button
  77. v-for="page in visiblePages"
  78. :key="page"
  79. class="admin--pagination-btn"
  80. :class="{ 'is-active': page === currentPage }"
  81. @click="changePage(page)"
  82. >{{ page }}</button>
  83. <button
  84. class="admin--pagination-btn"
  85. :disabled="currentPage === totalPages"
  86. @click="changePage(currentPage + 1)"
  87. title="다음"
  88. >▶</button>
  89. <button
  90. v-if="totalPages > 2"
  91. class="admin--pagination-btn"
  92. :disabled="currentPage === totalPages"
  93. @click="changePage(totalPages)"
  94. title="끝"
  95. >▶▶</button>
  96. </div>
  97. </div>
  98. </div>
  99. </template>
  100. <script setup>
  101. import { ref, computed, onMounted } from "vue";
  102. import { useRoute, useRouter } from "vue-router";
  103. definePageMeta({
  104. layout: "admin",
  105. middleware: ["auth"],
  106. });
  107. const route = useRoute();
  108. const router = useRouter();
  109. const { get } = useApi();
  110. const areaId = route.params.id;
  111. const isLoading = ref(false);
  112. const places = ref([]);
  113. const areaName = ref("");
  114. const onboardCount = ref(0);
  115. const fishingCount = ref(0);
  116. const currentPage = ref(1);
  117. const perPage = ref(10);
  118. const totalCount = ref(0);
  119. const totalPages = ref(0);
  120. // 페이지네이션 표시 페이지 번호
  121. const visiblePages = computed(() => {
  122. const pages = [];
  123. const maxVisible = 5;
  124. let start = Math.max(1, currentPage.value - Math.floor(maxVisible / 2));
  125. let end = Math.min(totalPages.value, start + maxVisible - 1);
  126. if (end - start < maxVisible - 1) start = Math.max(1, end - maxVisible + 1);
  127. for (let i = start; i <= end; i++) pages.push(i);
  128. return pages;
  129. });
  130. // 데이터 로드
  131. const loadPlaces = async () => {
  132. isLoading.value = true;
  133. const { data, error } = await get(`/area/${areaId}/places`, {
  134. params: { page: currentPage.value, per_page: perPage.value },
  135. });
  136. if (!error && data?.success && data?.data) {
  137. places.value = data.data.items || [];
  138. areaName.value = data.data.area_name || "";
  139. onboardCount.value = data.data.onboard_count || 0;
  140. fishingCount.value = data.data.fishing_count || 0;
  141. totalCount.value = data.data.total || 0;
  142. totalPages.value = data.data.total_pages || 0;
  143. }
  144. isLoading.value = false;
  145. };
  146. // 페이지 변경
  147. const changePage = (page) => {
  148. if (page < 1 || page > totalPages.value) return;
  149. currentPage.value = page;
  150. loadPlaces();
  151. window.scrollTo({ top: 0, behavior: "smooth" });
  152. };
  153. // 이동
  154. const goToPlace = (p) => {
  155. if (p.place_type === "onboard") {
  156. router.push(`/site-manager/onboard/detail/${p.id}`);
  157. } else if (p.place_type === "fishing") {
  158. router.push(`/site-manager/fishing/detail/${p.id}`);
  159. }
  160. };
  161. const goBack = () => router.push(`/site-manager/area/detail/${areaId}`);
  162. // 날짜만
  163. const formatDate = (dateString) => {
  164. if (!dateString) return "-";
  165. const date = new Date(dateString.replace(" ", "T"));
  166. if (isNaN(date.getTime())) return dateString;
  167. return date.toLocaleDateString("ko-KR", { year: "numeric", month: "2-digit", day: "2-digit" });
  168. };
  169. onMounted(() => {
  170. loadPlaces();
  171. });
  172. </script>